package com.hsq.db137.demos.seriver.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hsq.db137.demos.mapper.MenuinfoMapper;
import com.hsq.db137.demos.entity.Menuinfo;
import com.hsq.db137.demos.seriver.MenuinfoService;
/**
 * @Author: hsq加油
 * @CreateTime: 2024/12/24-11:48
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class MenuinfoServiceImpl extends ServiceImpl<MenuinfoMapper, Menuinfo> implements MenuinfoService{
@Autowired
private MenuinfoMapper menuinfoMapper;

 /*   *//**
     * 查询一级菜单
     * @param id 用户id
     * @return 菜单类
     *//*
    @Override
    public List<Menuinfo> selectListOne(int id) {
        return menuinfoMapper.selectListOne(id);
    }

    *//**
     * 查询二级菜单
//     * @param id 用户id
     * @return 菜单类
     *//*
    @Override
    public List<Menuinfo> selectListTwo(int id) {
        return menuinfoMapper.selectListTwo(id);
    }*/

    /**
     * 查询所属某一级菜单的所有二级菜单
     * @param parentId 一级菜单ID
     * @return 集合
     */
    @Override
    public List<Menuinfo> selectMenuTwo(int parentId) {
        QueryWrapper<Menuinfo> wrapper = new QueryWrapper<>();
        wrapper.eq("parentId", parentId);
        return menuinfoMapper.selectList(wrapper);
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Menuinfo> selectListAll(String label) {
        QueryWrapper<Menuinfo> wrapper = new QueryWrapper<>();
        if (label!=null){
            wrapper.like("label", label);
        }
        return menuinfoMapper.selectList(wrapper);
    }



    /**
     * 新增新的一级菜单
     * @param menuinfo
     * @return
     */
    @Override
    public String insertMenuOne(Menuinfo menuinfo) {
        return menuinfoMapper.insert(menuinfo)>0?"新增成功":"新增失败";
    }

    /**
     * 新增新的二级菜单
     * @param menuinfo
     * @return
     */
    @Override
    public String insertMenuTwo(Menuinfo menuinfo) {
        return menuinfoMapper.insert(menuinfo)>0?"新增成功":"新增失败";
    }

    /**
     * 老师查询
     * @param userid
     * @return
     */
    @Override
    public List<Menuinfo> selectList(int userid) {
        return menuinfoMapper.selectListByUid(userid);
    }

    /**
     * 根据id修改
     * @param menuinfo 对象
     * @return 提示语句
     */
    @Override
    public String updateMenuOne(Menuinfo menuinfo) {
        return menuinfoMapper.updateById(menuinfo)>0?"修改成功":"修改失败";
    }

    /**
     * 根据id查询
     * @param id 菜单id
     * @return 对象
     */
    @Override
    public Menuinfo selectMenuOne(int id) {
        return menuinfoMapper.selectById(id);
    }

    /**
     * 删除一级菜单
     * @param id
     * @return
     */
    @Override
    public String deleteMenuOne(int id) {
        QueryWrapper<Menuinfo> wrapper = new QueryWrapper<>();
        wrapper.eq("parentid", id);
        String s = menuinfoMapper.delete(wrapper) > 0 ? "删除成功" : "删除失败";
        System.out.println("s = " + s);
//        if (s.equals("删除成功")){
            return menuinfoMapper.deleteById(id)>0?"删除成功":"删除失败";
//        }
//       return s;
    }

    /**
     * 删除二级菜单
     * @param id
     * @return
     */
    @Override
    public String deleteMenuTwo(int id) {
        return menuinfoMapper.deleteById(id)>0?"删除成功":"删除失败";
    }
}
